package com.henz4help.app.common;

import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class AppInfo {
	private static AppInfo mAppInfo;
	
	private Context mContext;
	
	private int mDisplayWidth;
	private int mDisplayHeight;
	private int mHeightPixel;
	private int mWidthPixel;
	private int mDensityDpi;
	
	private float mXdpi;
	private float mYdpi;
	private float mDensity;
	
	private String mPhoneNum;
	
	public static AppInfo getInstance(Context ctx) {
		if(mAppInfo == null) 
			mAppInfo = new AppInfo(ctx);
		
		return mAppInfo;
	}
	
	public AppInfo(Context ctx) {
		mContext = ctx;
		getDeviceData();
		getPhoneNum();
	}
	
	public int getmDisplayWidth() { return mDisplayWidth; }
	public int getmDisplayHeight() {	return mDisplayHeight; }
	public int getmDensityDpi() {	return mDensityDpi; }
	public float getmDensity() { return mDensity; }
	public int getmHeightPixel() { return mHeightPixel; }
	public int getmWidthPixel() { return mWidthPixel; }
	public float getmXdpi() { return mXdpi; }
	public float getmYdpi() { return mYdpi; }
	public String getmPhoneNum() { return mPhoneNum; }
	
	@SuppressWarnings("deprecation")
	private void getDeviceData() {
		Display display = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		
		Util.Log("Build.VERSION.SDK_INT : " + Build.VERSION.SDK_INT);
		if(Build.VERSION.SDK_INT >= 13) {
			Point outSize = new Point();
			//display.getSize(outSize);
			mDisplayWidth = outSize.x;
			mDisplayHeight = outSize.y;
		} else {
			mDisplayWidth = display.getWidth();
			mDisplayHeight = display.getHeight();
		}
		
		DisplayMetrics displayMetrics = new DisplayMetrics();
		display.getMetrics(displayMetrics);
		mDensity = displayMetrics.density;
		mDensityDpi = displayMetrics.densityDpi;
		mHeightPixel = displayMetrics.heightPixels;
		mWidthPixel = displayMetrics.widthPixels;
		mXdpi = displayMetrics.xdpi;
		mYdpi = displayMetrics.ydpi;
	}
	
	private void getPhoneNum() {
		TelephonyManager telmgr = (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
		String phoneNum = telmgr.getLine1Number();
		
		if(phoneNum == null)
			phoneNum = "01000000000";
		
		mPhoneNum = phoneNum;
	}
}
